package com.power.sifa.correction.dao;

import com.power.sifa.correction.model.Crw_rule_person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.correction.model.Crw_rule_group;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 预警规则的人群分组 持久层(hibernate)
 */

public interface Crw_rule_groupDao extends JpaRepository<Crw_rule_group, Serializable>, JpaSpecificationExecutor<Crw_rule_group>, Repository<Crw_rule_group, Serializable>, Crw_rule_groupDaoCustom<Crw_rule_group, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Crw_rule_group s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<String> ids);

   @Query(" from Crw_rule_group s where s.id in (:ids) ")
   List<Crw_rule_group> findByIds(@Param("ids") List<String> ids);

   @Query(" from Crw_rule_group s where s.grpid in (:groupIds)")
   List<Crw_rule_group> getRuleByGroupIds(@Param("groupIds") List<String> groupIds);

   @Query(" from Crw_rule_group s where s.grpid = :groupId")
   List<Crw_rule_group> getRuleByGroupIds(@Param("groupId") String groupId);

   @Modifying
   @Transactional
   @Query("delete  from Crw_rule_group s where  s.ruleid = :ruleId ")
    void removeByRuleId(@Param("ruleId") String ruleId);

   @Transactional
   @Query(" from Crw_rule_group s where  s.ruleid = :ruleId ")
   List<Crw_rule_person> findByRuleId(@Param("ruleId") String ruleId);

   @Modifying
   @Transactional
   @Query("delete  from Crw_rule_group s where  s.ruleid in (:ruleIds) ")
   void removeByRuleIds(@Param("ruleIds")List<String> list);

   @Transactional
   @Query(" from Crw_rule_group s where s.ruleid in (:ruleIds) ")
   List<Crw_rule_group> findByRuleIds(@Param("ruleIds") List<String> list);

   @Query(value = "select s.grpid from Crw_rule_group s where s.ruleid = :ruleId",nativeQuery = true)
   List<String> findGroupIdsByRuleId(String ruleId);
}
